package com.xhu.rjsx2.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xhu.rjsx2.pojo.Course;
import com.xhu.rjsx2.pojo.vo.CourseVO;
import com.xhu.rjsx2.pojo.vo.PageVO;
import com.xhu.rjsx2.service.CourseService;
import com.xhu.rjsx2.mapper.CourseMapper;
import com.xhu.rjsx2.util.BeanCopyUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author ZQ
* @description 针对表【course】的数据库操作Service实现
* @createDate 2023-05-08 21:02:40
*/
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course>
    implements CourseService{

    @Override
    public PageVO listAllCoursePage(Integer pageNum, Integer pageSize,String courseCoach,String courseName,Integer courseTime) {
        LambdaQueryWrapper<Course> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(!StrUtil.isBlankIfStr(courseCoach),Course::getCourseCoach,courseCoach)
                .like(!StrUtil.isBlankIfStr(courseName),Course::getCourseName,courseName)
                .eq(!StrUtil.isBlankIfStr(courseTime),Course::getCourseTime,courseTime);
        Page<Course> page = new Page<>(pageNum, pageSize);
        page(page,queryWrapper);
        List<CourseVO> courseVOList = BeanCopyUtils.copyBeanList(page.getRecords(), CourseVO.class);
        return new PageVO(courseVOList,page.getTotal());
    }
}




